package com.leviassaf.androidbasics;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.SlidingDrawer;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;

//83
public class Slider extends Activity implements OnClickListener, OnCheckedChangeListener, OnDrawerOpenListener
{
	
	SlidingDrawer slidingdrawer;
	Button btnSlide;
	CheckBox chkSlidable;
	
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sliding);

		btnSlide = (Button)findViewById(R.id.btnSlide);
		Button handleOpen = (Button)findViewById(R.id.handleOpen);
		Button handleToggle = (Button)findViewById(R.id.handleToggle);
		Button handleClose = (Button)findViewById(R.id.handleClose);
		chkSlidable = (CheckBox)findViewById(R.id.chkSlidable);

		slidingdrawer = (SlidingDrawer)findViewById(R.id.slidingdrawer);
		slidingdrawer.setOnDrawerOpenListener(this);
		btnSlide.setText("Slide me up");

		chkSlidable.setOnCheckedChangeListener(this);
		handleOpen.setOnClickListener(this);
		handleToggle.setOnClickListener(this);
		handleClose.setOnClickListener(this);

		this.setTitle(String.format("%s-%s", this.getTitle().toString(), this.getClass().getSimpleName()));
	}

	@SuppressWarnings("deprecation")
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()){
			case R.id.handleOpen:
				slidingdrawer.open();
				break;
			case R.id.handleToggle:
				slidingdrawer.toggle();
				break;
			case R.id.handleClose:
				slidingdrawer.close();
				break;
		}
		if (slidingdrawer.isOpened()){
			btnSlide.setText("Slide me down");
		}
		else{
			btnSlide.setText("Slide me up");
		}
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		// TODO Auto-generated method stub
		if (buttonView.isChecked()){
			slidingdrawer.lock();
			chkSlidable.setText("Unlock slider");
		}
		else{
			slidingdrawer.unlock();
			chkSlidable.setText("Lock slider");
		}
	}

	@Override
	public void onDrawerOpened() {
		// TODO Auto-generated method stub
		MediaPlayer mediaplayer = MediaPlayer.create(this, R.raw.explosion);
		mediaplayer.start();
	}

}
